 if SERVER then AddCSLuaFile( "Tag.lua" ) end

local GM = IMiniGame.New();
GM["Info"] = {
	["Name"] = "Tag",
	["Version"] = "1.0",
	["up_date"] = "21 November 2010",
	["Author"] = {
		["Name"] = "Ningaglio",
		["Email"] = "Ningaglio@CitronGamers.com",
		["URL"] = "http://www.citrongamers.com"
	},
	["Info"] = "A replica of the childrens game : Tag",
	["Description"] = "Make sure you're not it!",
	["Icon"] = "gui/silkicons/brick_add"
}

function GM.Functions.OnPreLoad( )
	for k,v in pairs( player.GetAll() ) do
		v.Tag = false
	end
	return true
end

function GM.Functions.OnPostLoad( )
	local b = player.GetAll()[ math.random( #player.GetAll() ) ]
	b.Tag = true
	PrintMessage( HUD_PRINTCENTER , b:Nick() .. " Is It!!" )
end

function GM.Functions.OnUnload( )
	for k,v in pairs( player.GetAll() ) do
		v.Tag = nil
	end
	return true 
end

function GM.Hooks.KeyPress( Pl , Key )
	if Pl.Tag == true then
		if ( Key == IN_USE ) then
			if ( Pl:IsValid() ) then
				local trace = util.GetPlayerTrace( Pl )
				if trace.Entity then
					if trace.Entity:IsValid()/* and trace.Entity:IsPlayer() */then
						trace.Entity.Tag = true
						Pl.Tag = false
						PrintMessage( HUD_PRINTCENTER , trace.Entity:Nick() .. " Is It!!" )
						print( trace.Entity:Nick() .. " Is It!!" )
					end
				end
			end
		end
	end
end

function GM.Hooks.PlayerLoadout( pl ) return true end
function GM.Hooks.SpawnMenuEnabled() return false end
function GM.Hooks.SpawnMenuOpen() return false end
function GM.Hooks.ContextMenuOpen() return false end
function GM.Hooks.PopulateToolMenu() return false end
function GM.Hooks.PlayerNoClip() return false end
function GM.Hooks.CanPlayerSuicide() return false end

GM:Register()